{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c21f006c",
   "metadata": {},
   "source": [
    "# 本周学习目标\n",
    "> 1. while循环\n",
    "> 2. 购物车实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05288e0c",
   "metadata": {},
   "source": [
    "## 1.while循环\n",
    "* 回顾：for循环：for+range()可以指定循环的次数-->关于网页URL队列的抓取实践\n",
    "* while循环：当某种条件成立时，停止循环\n",
    "* while True;无限循环/死循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4a04cf19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿，我是沙 0\n",
      "你是风儿，我是沙 1\n"
     ]
    }
   ],
   "source": [
    "# 1. 指定次数\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿，我是沙\",count)\n",
    "    count = count+1\n",
    "    if count == 2:\n",
    "        break # break 终止循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56e667d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2. while True循环，可以让用户重复输入\n",
    "# user01 = \"admin\"\n",
    "# password01 = \"123456\"\n",
    "\n",
    "while True:\n",
    "    username = input(\"账号：\")\n",
    "    password = input(\"密码：\")\n",
    "    if user01 == username and password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "        break # 中止循环\n",
    "    # 情景二：账号不存在或密码不正确，用户可以输入三次，三次之后一小时之后再来尝试\n",
    "    else:\n",
    "        if count<2:\n",
    "            print(\"账号不存在或密码不正确！请重新输入！您还有\"+star(2-count)+\"次尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号或密码不正确！请一小时再来尝试\")\n",
    "            break\n",
    "            count = count+1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e62b5799",
   "metadata": {},
   "source": [
    "## 2. 购物车项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "cb7ca68a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (3870203876.py, line 12)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [13]\u001b[1;36m\u001b[0m\n\u001b[1;33m    \u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "# 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "\n",
    "product_list = [\n",
    "    [\"香蕉\",5],\n",
    "    [\"芒果\",6],\n",
    "]\n",
    "AliPay = input(\"请输入余额：\")\n",
    "print(\"------商品列表------\")\n",
    "for i in range(2):\n",
    "    print(\"商品序号\",\"(\"+str(i)+\"): \",product_prace_list[i][0],str(product_list[i][1]+\"元\")      # 格式化输出   \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f0bb899e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77c464a6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
